package com.github.ecbp.common.security.vo;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * SpringSecurity需要的用户详情
 */
@Data
public class DefaultUserDetails implements UserDetails {
    private Long id;
    private String icon;
    private String loginPhone;
    private String loginName;
    private String username;
    private String password;
    private Boolean status;
    private DefaultUserPermission userPermission;
    private List grantedAuthorities;

    public DefaultUserDetails() {
    }

    public List getGrantedAuthorities() {
        return grantedAuthorities;
    }

    //返回当前用户的角色
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return grantedAuthorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return loginPhone;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return status;
    }
}
